/**
 * @CommonsHeader.java  COPYRIGHT xiaojian
 * 
 * Created on 2016年7月18日 下午3:48:54
 */
package xj.toolkit.bean;

import org.apache.commons.lang3.builder.ToStringBuilder;

/**
 * 拼装tcp报文的头信息，如果使用http，则部分信息写入到http header里面。
 * 
 * @see xiaojian.toolkit.netty.util.NettyConstants
 * 
 * @author <a href="mailto:cxj2000@gmail.com">xiaojian.cao</a>
 *
 */
public class CommonsHeader {

	public static final int HEADER_LENGTH = 33;

	public static final short UNKNOWN = 0;
	public static final short REQUEST = 1;
	public static final short RESPONSE = 2;
	public static final short NOTIFY = 3;

	// (index = 1, length = 1)
	private byte basicVer = 1;

	/**
	 * 默认为3，json格式数据。
	 * 
	 * 1 - xip; 2 - tlv; 3 - json
	 */
	// (index = 2, length = 2)
	private short payloadType = 3;

	/**
	 * REQUEST/RESPONSE/NOTITFY
	 */
	// (index = 3, length = 2)
	private short type = 0;

	// (index = 4, length = 2)
	private short idBytesLen = 0;

	// (index = 5, length = idBytesLen)
	private byte[] idBytes;

	// (index = 6, bytes = 4)
	private int reserved = 0;

	// (index = 7, byte = 4)
	private int messageCode;

	// (index = 8, bytes = 4)
	private int messageLength;

	public byte getBasicVer() {
		return basicVer;
	}

	public void setBasicVer(byte basicVer) {
		this.basicVer = basicVer;
	}

	public short getPayloadType() {
		return payloadType;
	}

	public void setPayloadType(short payloadType) {
		this.payloadType = payloadType;
	}

	public short getType() {
		return type;
	}

	public void setType(short type) {
		this.type = type;
	}

	public short getIdBytesLen() {
		return idBytesLen;
	}

	public void setIdBytesLen(short idBytesLen) {
		this.idBytesLen = idBytesLen;
	}

	public byte[] getIdBytes() {
		return idBytes;
	}

	public void setIdBytes(byte[] idBytes) {
		this.idBytes = idBytes;
	}

	public int getReserved() {
		return reserved;
	}

	public void setReserved(int reserved) {
		this.reserved = reserved;
	}

	public int getMessageLength() {
		return messageLength;
	}

	public void setMessageLength(int messageLength) {
		this.messageLength = messageLength;
	}

	public int getMessageCode() {
		return messageCode;
	}

	public void setMessageCode(int messageCode) {
		this.messageCode = messageCode;
	}

	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}

}
